package org.example.fileClient;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.bytes.ByteArrayDecoder;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
import org.example.util.MyByteArrayDecoder;

/**
 * @classname: ClientInitializer
 * @description: TODO
 * @author: kaiser
 * @date: 2024/3/16 17:47
 * @version: 1.0
 */
public class ClientInitializer extends ChannelInitializer<SocketChannel> {
    private static final MyByteArrayDecoder DECODER = new MyByteArrayDecoder();
    private static final ByteArrayEncoder ENCODER = new ByteArrayEncoder();

    private static final ClientHandler CLIENT_HANDLER = new ClientHandler();


    @Override
    public void initChannel(SocketChannel ch) {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new DelimiterBasedFrameDecoder(102400000, Unpooled.copiedBuffer("END".getBytes())));
        pipeline.addLast(DECODER);
        pipeline.addLast(ENCODER);
        pipeline.addLast(CLIENT_HANDLER);
    }
}
